<template>
  <div class="app-container">
    <div class="custom_card_0">
      <el-form :model="queryParams" inline ref="queryForm" label-width="115px">
        <el-form-item label="车牌号" prop="carNo" label-width="60px">
          <el-input v-model="queryParams.carNo" placeholder="请输入车牌号" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="是否达到预警值" prop="illegalType">
          <el-select v-model="queryParams.illegalType" placeholder="请选择" clearable>
            <el-option label="是" :value="1" />
            <el-option label="否" :value="2" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" size="small" icon="el-icon-search" @click="handleQuery">
            搜索
          </el-button>
          <el-button size="small" icon="el-icon-refresh" @click="resetQuery">
            重置
          </el-button>
        </el-form-item>

      </el-form>
    </div>

    <div class="custom_card">
      <el-table ref="tables" v-loading="loading" :data="dataList" border @sort-change="handleSortChange">

        <el-table-column label="车牌号" min-width="70px" align="center" prop="carNo">
          <template slot-scope="{row}">
            <el-button type="text" style="color: #5473e8" @click="goDetail(row.carId)">{{ row.carNo }}</el-button>
          </template>
        </el-table-column>

        <el-table-column label="违章累计次数" min-width="50px" align="center" prop="totalNum" sortable="custom"
          :sort-orders="['ascending', 'descending']" />
        <el-table-column label="违章累计罚款(元)" min-width="50px" align="center" prop="totalFines" sortable="custom"
          :sort-orders="['ascending', 'descending']" />
        <el-table-column label="违章累计扣分" min-width="50px" align="center" prop="totalScore" sortable="custom"
          :sort-orders="['ascending', 'descending']" />
        <el-table-column label="未处理违章累计次数" min-width="50px" align="center" prop="UnhandledNum" sortable="custom"
          :sort-orders="['ascending', 'descending']">
          <template slot-scope="{row}">
            <span
              :style="{ color: 1 === illegalSetData.numberEnable && row.UnhandledNum >= illegalSetData.earlyNumber ? '#ff4949' : '#606266' }">{{
                row.UnhandledNum
              }}</span>
          </template>
        </el-table-column>
        <el-table-column label="未处理违章累计罚款(元)" min-width="50px" align="center" prop="UnhandledFines" sortable="custom"
          :sort-orders="['ascending', 'descending']">
          <template slot-scope="{row}">
            <span
              :style="{ color: 1 === illegalSetData.moneyEnable && row.UnhandledFines >= illegalSetData.earlyMoney ? '#ff4949' : '#606266' }">{{
                row.UnhandledFines
              }}</span>
          </template>
        </el-table-column>
        <el-table-column label="未处理违章累计扣分" min-width="50px" align="center" prop="UnhandledScore" sortable="custom"
          :sort-orders="['ascending', 'descending']">
          <template slot-scope="{row}">
            <span
              :style="{ color: 1 === illegalSetData.scoreEnable && row.UnhandledScore >= illegalSetData.earlyScore ? '#ff4949' : '#606266' }">{{
                row.UnhandledScore
              }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新时间" min-width="100px" align="center" prop="updateTime" sortable="custom"
          :sort-orders="['ascending', 'descending']" />
        <el-table-column label="车型" min-width="200px" show-overflow-tooltip align="center" prop="carInfo" />
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </div>

  </div>
</template>

<script>
import { illegalStatics, illegalSet } from '@/api/car/illegal'
import Template from "@/views/contract";

export default {
  name: "VehicleIllegal",
  components: { Template },
  data() {
    return {
      // 查询参数
      queryParams: {
        carNo: null,
        illegalType: null,
        sort: null,
        order: null,
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      dataList: [],
      // 遮罩层
      loading: true,
      //违章配置数据
      illegalSetData: {},
    }
  },
  created() {
    this.getList()
    this.getIllegalSet()
  },
  methods: {
    /** 获取列表数据 */
    getList() {
      this.loading = true
      illegalStatics(this.queryParams).then(res => {
        this.dataList = res.rows
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    },

    getIllegalSet() {
      illegalSet().then(res => {
        this.illegalSetData = res.data
      })
    },

    //执行搜索
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    //重置搜索
    resetQuery() {
      this.queryParams = {
        carNo: null,
        illegalType: null,
        sort: null,
        order: null,
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryForm")
      this.$refs.tables.clearSort()
      this.handleQuery()
    },

    //跳转详情
    goDetail(id) {
      this.$router.push({ name: 'basic_detail', query: { id, index: '4' } })
    },

    handleSortChange(column) {
      this.queryParams.sort = column.prop
      this.queryParams.order = column.order === 'descending' ? 'desc' : column.order === 'ascending' ? 'asc' : column.order
      this.getList()
    },

  }

}
</script>

<style scoped></style>
